package com.sgcc.fj.pmos.e_fj_home.fragment;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.sgcc.fj.pmos.arouter.app.AppArouterPath;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.arouter.mall.MallArouterPath;
import com.sgcc.fj.pmos.arouter.personalcenter.PersonalCenterArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseFragment;
import com.sgcc.fj.pmos.common.bean.EventCenter;
import com.sgcc.fj.pmos.common.bean.PackageBean;
import com.sgcc.fj.pmos.common.bean.StoreInfoBean;
import com.sgcc.fj.pmos.common.utils.ArguConstant;
import com.sgcc.fj.pmos.common.utils.BurialPointUtils;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.fj.pmos.common.utils.ImmersionBarUtils;
import com.sgcc.fj.pmos.common.utils.Options;
import com.sgcc.fj.pmos.common.utils.UserManager;
import com.sgcc.fj.pmos.common.utils.VisibilConfig;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.e_fj_home.adapter.MerchantAdapter;
import com.sgcc.fj.pmos.e_fj_home.adapter.SetmealAdapter;
import com.sgcc.fj.pmos.e_fj_home.animation.TextSwitcherAnimation;
import com.sgcc.fj.pmos.e_fj_home.bean.AddressBean;
import com.sgcc.fj.pmos.e_fj_home.bean.ContracttExecutionBean;
import com.sgcc.fj.pmos.e_fj_home.bean.DynamicNetBean;
import com.sgcc.fj.pmos.e_fj_home.bean.HomeGoodsBean;
import com.sgcc.fj.pmos.e_fj_home.bean.StoreBean;
import com.sgcc.fj.pmos.e_fj_home.contract.HomeContract;
import com.sgcc.fj.pmos.e_fj_home.presenter.HomePresenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class HomeFragment extends MvpBaseFragment<HomePresenter> implements HomeContract.View {

    private RecyclerView mRlMerchant;
    private RecyclerView mRlSetmeal;
    private RelativeLayout mRlNotLogin;
    private RelativeLayout mRlDirectlyTrading;
    private RelativeLayout mRlNoMeal;
    private RelativeLayout mRlSigning;
    private RelativeLayout mRlGoContract;
    private RelativeLayout mRlGoSigning;
    private RelativeLayout mRlGoMarketSituation;
    private RelativeLayout mRlPoliciesRegulations;
    private RelativeLayout mRlMembersmarket;
    private RelativeLayout mRlMarketDynamic;
    private RelativeLayout rl_search;
    private MerchantAdapter mMerchantAdapter;
    private SetmealAdapter mSetmealAdapter;
    private SmartRefreshLayout mSmartRefreshLayout;
    private ImageView mIvMessage;
    private ImageView iv_title;
    private ImageView mIvIssuedInvitation;
    private TextView name_txt;
    private TextView user_type_txt;
    private TextView contract_time_txt;
    private TextView tips_txt;
    private TextView tvMoreStore;
    private TextView tvMoreGoods;
    private TextSwitcher mTextSwitcher;
    private RelativeLayout lsbk_rela;
    private TextView tv_place;
    private RelativeLayout rela_sfzh;
    private RelativeLayout rela_jsxx;
    private RelativeLayout rl_jiesuanxinxi;
    ContracttExecutionBean contracttExecution;
    private TextView tv_userenddate, tv_userenddate_title;
    private LinearLayout linner_contract;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_homepage_fj;
    }

    @Override
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBarUtils.initHomeColorBar(getActivity());
    }

    @Override
    public void onResume() {
        super.onResume();
        onChangePage();
    }

    private void onChangePage() {
        if (UserManager.isLogin()) {
            mRlNotLogin.setVisibility(View.GONE);
            mRlSigning.setVisibility(View.VISIBLE);
            mRlDirectlyTrading.setVisibility(View.GONE);
            mRlNoMeal.setVisibility(View.GONE);
            name_txt.setText(UserManager.getUserBean().getNickname());
//            if (TextUtils.equals("20", UserManager.getUserBean().getExtend().getMembersType())) {
//                user_type_txt.setText("零售用户");
//            } else {
//                user_type_txt.setText("——");
//            }
//            setTips("");
            mPresenter.getContractExecution(false);

        } else {
            mRlNotLogin.setVisibility(View.VISIBLE);
            mRlSigning.setVisibility(View.GONE);
            mRlDirectlyTrading.setVisibility(View.GONE);
            mRlNoMeal.setVisibility(View.GONE);
        }
    }

    @Override
    public boolean isBindEventBusHere() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(EventCenter eventCenter) {
        if (eventCenter.getEventCode() == ArguConstant.LOGOUT) {
            onChangePage();
        }
        if (eventCenter.getEventCode() == ArguConstant.REFRESH_GOODS_LIST) {
            mPresenter.getStoreList(true);
        }

        if (eventCenter.getEventCode() == ArguConstant.SELECTADDRESS) {
            AddressBean.DataBean.ObjListBean.ProvincesBean bean = (AddressBean.DataBean.ObjListBean.ProvincesBean) eventCenter.getData();
            String netProvinceName = bean.getNetProvinceName().replace("电力交易中心", "");
            if (Options.getInstance().getOnPlaceCallBackListener() != null) {
                UserManager.logout();
                Options.getInstance().getOnPlaceCallBackListener().callback(netProvinceName);
                getActivity().finish();
            }
        }
    }


    @Override
    protected void initViews() {
        super.initViews();
        name_txt = (TextView) mRootView.findViewById(R.id.name_txt);
        user_type_txt = (TextView) mRootView.findViewById(R.id.user_type_txt);
        contract_time_txt = (TextView) mRootView.findViewById(R.id.contract_time_txt);
        linner_contract = mRootView.findViewById(R.id.linner_contract);
        tips_txt = (TextView) mRootView.findViewById(R.id.tips_txt);
        tv_place = (TextView) mRootView.findViewById(R.id.tv_place);
        tv_place.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(HomeArouterPath.HOME_SELECTADDRESS)
                        .navigation();
            }
        });

        mRlMerchant = (RecyclerView) mRootView.findViewById(R.id.rl_merchant);
        mRlSetmeal = (RecyclerView) mRootView.findViewById(R.id.rl_setmeal);
        mRlNotLogin = (RelativeLayout) mRootView.findViewById(R.id.rl_not_login);
        mRlDirectlyTrading = (RelativeLayout) mRootView.findViewById(R.id.rl_directly_trading);
        mRlNoMeal = (RelativeLayout) mRootView.findViewById(R.id.rl_no_meal);
        mRlSigning = (RelativeLayout) mRootView.findViewById(R.id.rl_signing);
        mRlGoSigning = (RelativeLayout) mRootView.findViewById(R.id.rl_go_signing);
        mRlGoContract = (RelativeLayout) mRootView.findViewById(R.id.rl_go_contract);
        mRlGoMarketSituation = (RelativeLayout) mRootView.findViewById(R.id.rl_go_marketSituation);
        rl_search = (RelativeLayout) mRootView.findViewById(R.id.rl_search);

        mRlPoliciesRegulations = (RelativeLayout) mRootView.findViewById(R.id.rl_policies_regulations);
        mRlMembersmarket = (RelativeLayout) mRootView.findViewById(R.id.rl_membersmarket);
        mRlMarketDynamic = (RelativeLayout) mRootView.findViewById(R.id.rl_market_dynamic);

        mIvMessage = (ImageView) mRootView.findViewById(R.id.iv_message);
        mIvIssuedInvitation = (ImageView) mRootView.findViewById(R.id.iv_issued_invitation);
        iv_title = (ImageView) mRootView.findViewById(R.id.iv_title);
        mTextSwitcher = (TextSwitcher) mRootView.findViewById(R.id.textSwitcher);

        tvMoreStore = mRootView.findViewById(R.id.tvMoreStore);
        tvMoreGoods = mRootView.findViewById(R.id.tvMoreGoods);

        lsbk_rela = mRootView.findViewById(R.id.lsbk_rela);
        rela_sfzh = mRootView.findViewById(R.id.rela_sfzh);
        rela_jsxx = mRootView.findViewById(R.id.rela_jsxx);
        tv_userenddate_title = mRootView.findViewById(R.id.tv_userenddate_title);
        tv_userenddate = mRootView.findViewById(R.id.tv_userenddate);

        rl_jiesuanxinxi = mRootView.findViewById(R.id.rl_jiesuanxinxi);
        if (!VisibilConfig.isShowVisibil()) {
            rela_sfzh.setVisibility(View.INVISIBLE);
            rela_jsxx.setVisibility(View.INVISIBLE);
            mIvMessage.setVisibility(View.INVISIBLE);
        }
        mSmartRefreshLayout = (SmartRefreshLayout) mRootView.findViewById(R.id.smartRefreshLayout);

        mRlMerchant.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        mRlSetmeal.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        mRlMerchant.setItemAnimator(new DefaultItemAnimator());
        mRlSetmeal.setItemAnimator(new DefaultItemAnimator());

        rela_sfzh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtils.showShort("敬请期待");
//                if (UserManager.toLogin()) {
//                    if (contracttExecution != null) {
//                        ARouter.getInstance()
//                                .build(HomeArouterPath.HOME_USERTYPEINFO)
//                                .withString("userType", contracttExecution.getData().getUserType())
//                                .navigation();
//                    } else {
//                        ToastUtils.showShort("合约执行情况获取失败");
//                    }
//                }
            }
        });
        rela_jsxx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (UserManager.toLogin()) {
                    ARouter.getInstance()
                            .build(MallArouterPath.MALL_INVITATIONLIST)
                            .navigation();
                }


            }
        });
        rl_jiesuanxinxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //结算信息
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_SETTLEMENTINFO)
                        .navigation();
                BurialPointUtils.onBurialPoint(BurialPointUtils.mPoint.INFORMATION_DISCLOSURE);
//                //信息披露
//                ARouter.getInstance()
//                        .build(HomeArouterPath.HOME_INFORMATIONDISCLOSURE)
//                        .navigation();
            }
        });

        mMerchantAdapter = new MerchantAdapter(mContext);
        mMerchantAdapter.setOnItemClickListener(new MerchantAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, StoreInfoBean bean) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_STOREHOMEPAGE)
                        .withString("membersSdId", bean.getMembersSdId())
                        .navigation();
            }
        });

        mSetmealAdapter = new SetmealAdapter(mContext);
        mSetmealAdapter.setOnItemClickListener(new SetmealAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, PackageBean bean) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_PACKAGEDETAILS)
                        .withString("combName", bean.getCombCode())
                        .withBoolean("isBlue", "1".equals(bean.getpNum()) && ("03".equals(bean.getMainType()) || "04".equals(bean.getMainType())) &&
                                "0".equals(bean.getMainItemType()) &&
                                ("0".equals(bean.getMainDifType()) || TextUtils.isEmpty(bean.getMainDifType())))

                        .navigation();
            }
        });

        mRlMerchant.setAdapter(mMerchantAdapter);
        mRlSetmeal.setAdapter(mSetmealAdapter);

        mRlNotLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(AppArouterPath.APP_LOGIN)
                        .navigation();
            }
        });

        mIvIssuedInvitation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (UserManager.toLogin()) {
                    ARouter.getInstance()
                            .build(MallArouterPath.MALL_INVITATIONLIST)
                            .navigation();
                }
            }
        });

        mRlGoContract.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //TODO 点击后跳转到本月合约详情
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_ORDER));

            }
        });

        rl_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_SEARCH)
                        .navigation();
            }
        });


        mRlGoSigning.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SPUtils.getInstance().put("mallPage", 1);
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_SIGNING));
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_MALL_STORE_OR_GOODS, 0));
            }
        });
        mRlGoMarketSituation.setOnClickListener(new View.OnClickListener() {//市场行情
            @Override
            public void onClick(View view) {
//                ARouter.getInstance()
//                        .build(HomeArouterPath.HOME_MARKET_SITUATION)
//                        .navigation();
                ToastUtils.showShort("敬请期待");
            }
        });

        mIvMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(PersonalCenterArouterPath.PERSONALCENTER_MESSAGE)
                        .navigation();
            }
        });
        tvMoreStore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_SIGNING));
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_MALL_STORE_OR_GOODS, 1));
                SPUtils.getInstance().put("mallPage", 2);
            }
        });
        tvMoreGoods.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_SIGNING));
                EventBus.getDefault().post(new EventCenter<>(ArguConstant.GO_MALL_STORE_OR_GOODS, 0));
                SPUtils.getInstance().put("mallPage", 1);
            }
        });

        mRlPoliciesRegulations.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(HomeArouterPath.HOME_POLICIESREGULATIONS)
                        .navigation();
            }
        });
        mRlMembersmarket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(HomeArouterPath.HOME_MEMBERSMARKET)
                        .navigation();
            }
        });
        mRlMarketDynamic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(HomeArouterPath.HOME_MARKETDYNAMIC)
                        .navigation();
            }
        });
        lsbk_rela.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(HomeArouterPath.HOME_RETAILQA)
                        .navigation();
            }
        });


        mSmartRefreshLayout.setEnableLoadMore(false);
        mSmartRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.getContractExecution(false);
            }
        });

        mPresenter.getStoreList(true);
        mPresenter.getMarketListData();
    }

    @Override
    protected HomePresenter createPresenter() {
        return new HomePresenter();
    }

    @Override
    public void queryContractSuccess(ContracttExecutionBean response, boolean isloading) {
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getData() != null) {
                    contracttExecution = response;
                    user_type_txt.setText(response.getData().getUserType());
//                    setTips(response.getData());
                    if (!TextUtils.isEmpty(response.getData().getEndDate())) {
                        tv_userenddate.setText(DateUtils.getStrng_to_Times_ymd_3(response.getData().getEndDate()));
                    } else {
                        tv_userenddate.setText("永久有效");
                    }
                    if (TextUtils.equals("零售用户", response.getData().getUserType())) {
                        tv_userenddate.setVisibility(View.VISIBLE);
                        tv_userenddate_title.setVisibility(View.VISIBLE);
                        linner_contract.setVisibility(View.VISIBLE);
                        tv_userenddate_title.setVisibility(View.VISIBLE);
                    } else {
                        linner_contract.setVisibility(View.GONE);
                    }
                    if (response.getData().getNowStartDate() == null) {
                        contract_time_txt.setText("本月未签订合约");
                    } else {
                        contract_time_txt.setText(DateUtils.getStrng_to_Times_ymd_3((String) response.getData().getNowStartDate()) +
                                "~" + DateUtils.getStrng_to_Times_ymd_3((String) response.getData().getNowEndDate()));
                    }
                } else {
                    contract_time_txt.setText("本月未签订合约");
                }
            } else {
//                ToastUtils.showShort(response.getMsg());
            }
        }
        mPresenter.getStoreList(isloading);
    }

    @Override
    public void queryContractFailed() {
        mSmartRefreshLayout.finishRefresh();
        ToastUtils.showShort("请求合约执行情况失败");
    }

    @Override
    public void queryStoreListSuccess(StoreBean response, boolean isloading) {
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getRows() != null) {
                    mMerchantAdapter.setNewData(response.getRows());
                    mPresenter.getRatioCurve(isloading);
                }
            } else {
                mSmartRefreshLayout.finishRefresh();
            }
        }
        mSmartRefreshLayout.finishRefresh();
    }

    @Override
    public void queryStoreListFailed() {
        mSmartRefreshLayout.finishRefresh();
    }

    @Override
    public void queryGoodsSuccess(HomeGoodsBean response, boolean isloading) {
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getData() != null) {
                    mSetmealAdapter.setNewData(response.getData().getData());
                }
            }
        }
        mSmartRefreshLayout.finishRefresh();
    }

    @Override
    public void queryGoodsFailed() {
        mSmartRefreshLayout.finishRefresh();
    }

    @Override
    public void queryNetDataSuccess(DynamicNetBean bean) {
        if (bean != null) {
            if (bean.getCode() == 200) {
                List<String> texts = new ArrayList<>();
                for (int i = 0; i < bean.getData().getList().size(); i++) {
                    texts.add(bean.getData().getList().get(i).getTitle());
                }
                mTextSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
                    @Override
                    public View makeView() {
                        TextView t = new TextView(mContext);
                        t.setSingleLine(true);
                        t.setMaxLines(1);
                        t.setTextSize(11);
                        t.setEllipsize(TextUtils.TruncateAt.END);
                        return t;
                    }
                });
                new TextSwitcherAnimation(mTextSwitcher, texts).create();
            } else {
                ToastUtils.showShort(bean.getMsg());
            }
        } else {
            ToastUtils.showShort("市场动态获取失败");
        }
//        texts.add("《国家发展改革委 国家能源局关于印发〈电力中长期交易基本规则〉的通知》（发改能源规〔2020〕889号）");
//        texts.add("《国家发展改革委 国家能源局关于印发售电公司管理办法的通知》（发改体改规〔2021〕1595号）");
//        texts.add("《国家发展改革委关于进一步深化燃煤发电上网电价市场化改革的通知》（发改价格〔2021〕1439号）");
//        texts.add("《中共中央 国务院关于进一步深化电力体制改革的若干意见》（中发〔2015〕9号）");
//        texts.add("山西能源监管办 山西省发展改革委《山西省电力中长期交易实施细则》（晋监能〔2020〕16号）");
//        texts.add("山西省电力市场规则汇编（试运行V12）");
//        texts.add("山西省能源局 山西能源监管办《关于印发售电公司管理实施细则的通知》（晋能源电力发〔2022〕183号）");

    }


    private void setTips(String startTime, String endTime) {
        String time1 = TimeUtils.getNowString();
        int month = Integer.valueOf(time1.substring(5, 7));
        int day = Integer.valueOf(time1.substring(8, 10));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
        try {
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
            if (day < 16) {
                Date nowDate = DateUtils.nextMonthDate(1);
                if (startDate.compareTo(nowDate) < 0 && nowDate.compareTo(endDate) < 0) {
                    //当前时间再合约周期范围内
                    tips_txt.setVisibility(View.GONE);
                    iv_title.setVisibility(View.GONE);
                } else {
                    tips_txt.setVisibility(View.VISIBLE);
                    iv_title.setVisibility(View.VISIBLE);
                    tips_txt.setText("距" + (month + 1) + "月套餐签订截止时间只剩" + (15 - day) + "天，请尽快完成签约！");
                }
            } else {

                Date nowDate = DateUtils.nextMonthDate(2);
                if (startDate.compareTo(nowDate) < 0 && nowDate.compareTo(endDate) < 0) {
                    //当前时间再合约周期范围内
                    tips_txt.setVisibility(View.GONE);
                    iv_title.setVisibility(View.GONE);
                } else {
                    tips_txt.setVisibility(View.VISIBLE);
                    iv_title.setVisibility(View.VISIBLE);
                    tips_txt.setText("距" + (month + 2) + "月套餐签订截止时间只剩" + (45 - day) + "天，请尽快完成签约！");
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }


    private void setTips(ContracttExecutionBean.DataDTO bean) {
        if (TextUtils.equals("零售用户", bean.getUserType())) {
            String nextTime = bean.getAfterContractExeciton();
            if (!TextUtils.isEmpty(nextTime) && nextTime.startsWith("20")) {
                tips_txt.setVisibility(View.VISIBLE);
                iv_title.setVisibility(View.VISIBLE);
                int nextMonth = 0;
                try {
                    nextMonth = Integer.valueOf(nextTime.substring(5, nextTime.length()));
                } catch (Exception e) {
                    ToastUtils.showShort("合约执行时间返回有误");
                }
                String time1 = TimeUtils.getNowString();
                int nowDay = Integer.valueOf(time1.substring(8, 10));
                if (nowDay < 16) {
                    tips_txt.setText("距" + nextMonth + "月套餐签订截止时间只剩" + (15 - nowDay) + "天，请尽快完成签约！");
                } else {
                    tips_txt.setText("距" + nextMonth + "月套餐签订截止时间只剩" + (45 - nowDay) + "天，请尽快完成签约！");
                }
            } else {
                ToastUtils.showShort("服务器合约周期返回有误");
                tips_txt.setVisibility(View.GONE);
                iv_title.setVisibility(View.GONE);
            }
            if (!TextUtils.equals("0", bean.getCount())) {
                //  setTips((String) response.getData().get(0).getNowStartDate(), (String) response.getData().get(0).getNowEndDate());
                tips_txt.setVisibility(View.GONE);
                iv_title.setVisibility(View.GONE);
            }
        } else {
            tips_txt.setVisibility(View.VISIBLE);
            iv_title.setVisibility(View.VISIBLE);
            tips_txt.setText("如果需要参与零售交易，请先进行身份转换。");
        }
        tips_txt.setVisibility(View.GONE);
        iv_title.setVisibility(View.GONE);
    }
}
